package cn.tedu.hotel.controller;

import cn.tedu.hotel.pojo.dto.BillAddNewDTO;
import cn.tedu.hotel.pojo.vo.BillLIstItemVO;
import cn.tedu.hotel.service.IBillService;
import cn.tedu.hotel.web.JsonPage;
import cn.tedu.hotel.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *  处理订单的控制器类
 */
@Api(tags = "11. 订单管理模块")
@Slf4j
@RestController
@RequestMapping("/bills")
public class BillController {

    @Autowired
    private IBillService billService;

    public BillController(){
        log.debug("创建控制器：BillController");
    }


    @ApiOperation("新增订单")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(BillAddNewDTO billAddNewDTO){
        log.debug("开始处理【新增订单】的请求,参数：{}",billAddNewDTO);
        billService.addNew(billAddNewDTO);
        return JsonResult.ok();
    }

    @GetMapping("/page")
    @ApiOperation("分页查询所有订单")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "页码",name = "page" ,example = "1"),
            @ApiImplicitParam(value = "每页条数",name = "pageSize" ,example = "6")
    })
    public JsonResult<JsonPage<BillLIstItemVO>> pageBills(
            Integer page,Integer pageSize){
        log.debug("开始处理【分页查询订单列表】的请求");
        //  执行分页查询的业务逻辑层
        JsonPage<BillLIstItemVO> jsonPage= billService.getAllBillsByPage(page,pageSize);
        return JsonResult.ok(jsonPage);

    }




}
